package services.robot

import common._
import java.util.Observable

class Robot(siteNode: SiteNode) extends Observable with Runnable {
  def run() {
    handleCategory(siteNode)
  }
  def handleCategory(siteNode: SiteNode) {
    //TODO: notify about new category
    siteNode.categories.size match {
      case 0 => {
        handleProductsPage(1, siteNode)
      }
      case n => siteNode.categories.foreach(handleCategory)
    }
  }
  def handleProductsPage(pageNumber: Int, siteNode: SiteNode) {
    val productsPage = siteNode.getProductsPage(pageNumber);
    productsPage.items.foreach(handleProduct)
    if (productsPage.nextPageExists)
      handleProductsPage(pageNumber + 1, siteNode)
  }
  def handleProduct(siteNode: ProductNode) {

  }
}
